//
//  MyWalletController.m
//  OnionHome
//
//  Created by fengjie on 2019/9/14.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "MyWalletController.h"
#import "MyWalletDetailListController.h"
#import "AddBalanceController.h"

@interface MyWalletController ()
/**余额*/
@property (nonatomic,strong)UILabel*balanceNumber;
/**累计收益*/
@property (nonatomic,strong)UILabel*cumulLab;
/**今日收益*/
@property (nonatomic,strong)UILabel*todayLab;

@end

@implementation MyWalletController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"我的钱包";
    self.bg_ImageView.image = IMAGE_NAMED(@"Wallet_bg");
    if (@available(iOS 11.0, *)) {
        self.scrollview.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    [self setNavItemView];
    [self createUI];

}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName :UIColorFromRGB(0xFFFFFF), NSFontAttributeName : SYSTEMFONT(19)}];

}
-(void)setNavItemView{
    
    [self addNavigationItemWithImageNames:@[@"back1"] isLeft:YES target:self action:@selector(backBtnClicked) tags:nil];
    
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"明细" forState:UIControlStateNormal];
    [button setTitleColor:UIColorFromRGB(0xFFFFFF) forState:UIControlStateNormal];
    button.titleLabel.font = SYSTEMFONT(16);
    kWeakSelf(weakSelf);
    [button addActionHandler:^{
        [weakSelf.navigationController pushViewController:[MyWalletDetailListController new] animated:YES];
    }];
    
    UIBarButtonItem * item = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.rightBarButtonItem = item;
}
-(void)createUI{
    UILabel * topTitle = UILabel.new;
    topTitle.textColor = UIColor.whiteColor;
    topTitle.font = PingFangSC_Medium(18);
    topTitle.text = @"当前余额";
    
    UILabel * leftTitle = UILabel.new;
    leftTitle.textColor = UIColor.whiteColor;
    leftTitle.font = PingFangSC_Medium(16);
    leftTitle.text = @"累计收益";
    leftTitle.textAlignment = NSTextAlignmentCenter;

    UILabel * rightTitle = UILabel.new;
    rightTitle.textColor = UIColor.whiteColor;
    rightTitle.font = PingFangSC_Medium(16);
    rightTitle.text = @"今日收益";
    rightTitle.textAlignment = NSTextAlignmentCenter;
    
    UIButton * oneButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [oneButton setTitle:@"提现" forState:UIControlStateNormal];
    [oneButton setTitleColor:UIColorFromRGB(0x454F44) forState:UIControlStateNormal];
    [oneButton setBackgroundImage:[UIImage createImageWithColor:UIColor.whiteColor] forState:UIControlStateNormal];
    oneButton.titleLabel.font = PingFangSC_Medium(18);
    ViewRadius(oneButton, 3);
    kWeakSelf(weakSelf);
    [oneButton addActionHandler:^{
        AddBalanceController * vc =[AddBalanceController new];
        vc.type = Extract;

        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];

    UIButton * twoButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [twoButton setTitle:@"充值" forState:UIControlStateNormal];
    [twoButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    [twoButton setBackgroundImage:[UIImage createImageWithColor:RGB(0, 153, 102)] forState:UIControlStateNormal];
    twoButton.titleLabel.font = PingFangSC_Medium(18);
    ViewRadius(twoButton, 3);
    
    [twoButton addActionHandler:^{
        AddBalanceController * vc =[AddBalanceController new];
        vc.type = AddBalance;

        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];


    [self.contenView addSubview:topTitle];
    [self.contenView addSubview:self.balanceNumber];
    [self.contenView addSubview:leftTitle];
    [self.contenView addSubview:rightTitle];
    [self.contenView addSubview:self.cumulLab];
    [self.contenView addSubview:self.todayLab];
    [self.contenView addSubview:oneButton];
    [self.contenView addSubview:twoButton];

    [topTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(110+K_TopHeight);
    }];
    
    [self.balanceNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(topTitle.mas_bottom).offset(25);
    }];
    [leftTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(70);
        make.top.mas_equalTo(self.balanceNumber.mas_bottom).offset(46);
    }];
    [rightTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-70);
        make.top.mas_equalTo(self.balanceNumber.mas_bottom).offset(46);
    }];
    
    [self.cumulLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(leftTitle);
        make.top.mas_equalTo(leftTitle.mas_bottom).offset(5);
    }];
    [self.todayLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(rightTitle);
        make.top.mas_equalTo(rightTitle.mas_bottom).offset(5);
    }];
    [oneButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(45);
        make.right.mas_equalTo(-45);
        make.height.mas_equalTo(50);
        make.top.mas_equalTo(self.todayLab.mas_bottom).offset(115);
    }];
    [twoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(45);
        make.right.mas_equalTo(-45);
        make.height.mas_equalTo(50);
        make.top.mas_equalTo(oneButton.mas_bottom).offset(20);
        make.bottom.mas_equalTo(-10);
    }];

}
#pragma mark ---懒加载

-(UILabel*)balanceNumber{
    if(!_balanceNumber){
        _balanceNumber=[UILabel new];
        _balanceNumber.textColor = UIColorFromRGB(0xFFFFFF);
        _balanceNumber.textAlignment = NSTextAlignmentCenter;
        _balanceNumber.font = BOLDSYSTEMFONT(40);
        _balanceNumber.text = @"60000";
    }
    return _balanceNumber;
}
-(UILabel*)cumulLab{
    if(!_cumulLab){
        _cumulLab=[UILabel new];
        _cumulLab.textColor = UIColorFromRGB(0xFFFFFF);
        _cumulLab.textAlignment = NSTextAlignmentCenter;
        _cumulLab.font = BOLDSYSTEMFONT(22);
        _cumulLab.text = @"10021元";
    }
    return _cumulLab;
}
-(UILabel*)todayLab{
    if(!_todayLab){
        _todayLab=[UILabel new];
        _todayLab.textColor = UIColorFromRGB(0xFFFFFF);
        _todayLab.textAlignment = NSTextAlignmentCenter;
        _todayLab.font = BOLDSYSTEMFONT(22);
        _todayLab.text = @"10元";
    }
    return _todayLab;
}

@end

